package model

import (
	"common/global"
	"gorm.io/gorm"
	"time"
)

type Doctors struct {
	Id                  int            `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	DoctorName          string         `gorm:"column:doctor_name;type:varchar(50);comment:医生姓名;not null;" json:"doctor_name"`                        // 医生姓名
	DoctorAge           int64          `gorm:"column:doctor_age;type:int;comment:医生年龄;default:NULL;" json:"doctor_age"`                              // 医生年龄
	Sex                 int            `gorm:"column:sex;type:int UNSIGNED;comment:1是男 2是女;default:NULL;" json:"sex"`                                // 1是男 2是女
	EducationDegree     string         `gorm:"column:education_degree;type:varchar(50);comment:学历学位;default:NULL;" json:"education_degree"`          // 学历学位
	StartWorkDate       time.Time      `gorm:"column:start_work_date;type:date;comment:开始工作时间;default:NULL;" json:"start_work_date"`                 // 开始工作时间
	GraduatedUniversity string         `gorm:"column:graduated_university;type:varchar(100);comment:毕业院校;default:NULL;" json:"graduated_university"` // 毕业院校
	Title               string         `gorm:"column:title;type:varchar(50);comment:职称;default:NULL;" json:"title"`                                  // 职称
	Specialty           string         `gorm:"column:specialty;type:varchar(50);comment:专业;default:NULL;" json:"specialty"`                          // 专业
	Department          string         `gorm:"column:department;type:varchar(50);comment:所属科室;default:NULL;" json:"department"`                      // 所属科室
	DoctorIntroduction  string         `gorm:"column:doctor_introduction;type:text;comment:医生介绍;" json:"doctor_introduction"`                        // 医生介绍
	CreateAt            time.Time      `gorm:"column:create_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"create_at"`
	UpdateAt            time.Time      `gorm:"column:update_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"update_at"`
	DeleteAt            gorm.DeletedAt `gorm:"column:delete_at;type:datetime(3);default:NULL;" json:"delete_at"`
}

func (Doctors) TableName() string {
	return "doctors"
}

func (d Doctors) ByInfo(doctorId int64) (*Doctors, error) {
	err := global.Db.Where("id=?", doctorId).Limit(1).Find(&d).Error
	return &d, err
}

func (d Doctors) ByList() (doctors []Doctors, err error) {
	err = global.Db.Find(&doctors).Error
	return doctors, err
}
